package com.vcc.boss.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.vcc.core.annotations.RestPack;
import com.vcc.core.exception.ProgramException;
import com.vcc.data.entity.BossUser;
import com.vcc.data.entity.User;
import com.vcc.data.entity.UserCard;
import com.vcc.service.client.vo.otp.ClientOtpVo;
import com.vcc.service.sa.BossUserUtil;
import com.vcc.service.service.OtpService;
import com.vcc.service.service.UserCardService;
import com.vcc.service.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("otp")
public class OtpController {


    @Resource
    private OtpService otpService;
    @Resource
    private UserCardService userCardService;
    @Resource
    private UserService userService;

    @RestPack
    @GetMapping("/list")
    @SaCheckLogin
    public List<ClientOtpVo> paging(
            Long userCardId
    ) {
        BossUser user = BossUserUtil.get();
        UserCard userCard = userCardService.getByIdOpt(userCardId).orElseThrow(() -> new ProgramException("用户卡不存在"));
        Long dealerId = userService.getDealerIdById(userCard.getUserId());
        if (!BossUserUtil.hasAllData() && !dealerId.equals(BossUserUtil.getId())) {
            throw new ProgramException("无权查看该用户的参数配置");
        }
        return otpService.listByUserCardId(
                userCardId
        );


    }


}
